//
//  STWelcomeController.m
//  OCVVeibo
//
//  Created by leergou on 16/7/23.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STWelcomeController.h"

@interface STWelcomeController ()

@property (nonatomic,strong) UIImageView *backgImageView;

@property (nonatomic,strong) UIImageView *iconImageView;

@property (nonatomic,strong) UILabel *titleLabel;


@end

@implementation STWelcomeController

- (void)loadView{
    //要记得调用弗雷方法
    [super loadView];
    
    self.view = self.backgImageView;
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    // 更新约束
    [self.iconImageView updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(100);
    }];
    
    // 动画效果
    [UIView animateWithDuration:5 animations:^{
        
        
        
    } completion:^(BOOL finished) {
        
            }];
    
    [UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
        [self.view layoutIfNeeded]; // view 的方法,通过约束产生动画-> layoutIfNeeded
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.25 animations:^{
            
             self.titleLabel.alpha = 1;
            
        } completion:^(BOOL finished) {
            
        [[NSNotificationCenter defaultCenter] postNotificationName:STSwitchRootVCNotification object:@"welcome"];

        }];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
}

// setupUI
- (void)setupUI{
    
    //添加控件
    [self.view addSubview:self.iconImageView];
    [self.view addSubview:self.titleLabel];
    // 添加约束
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(400);
        make.size.equalTo(CGSizeMake(90, 90));
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.iconImageView.bottom).offset(16);
    }];
    
}





#pragma mark - lazy

- (UIImageView *)backgImageView{
    if (!_backgImageView) {
        _backgImageView = [[UIImageView alloc] initWithImageName:@"ad_background"];
        
    }
    return _backgImageView;
}

- (UIImageView *)iconImageView{
    if (!_iconImageView) {
        
        _iconImageView = [[UIImageView alloc] initWithImageUrl:[STUserAccountVM sharedUserAccountTools].userAccountDTO.avatar_large placeHolderImage:@"avatar_default_big"];
        _iconImageView.layer.cornerRadius = 45;
        _iconImageView.layer.masksToBounds = YES;
        _iconImageView.layer.borderColor = ThemeColor.CGColor;
        _iconImageView.layer.borderWidth = 2;
    }
    return _iconImageView;
}

- (UILabel *)titleLabel{
    
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithTextColor:[UIColor darkGrayColor] textFont:18 maxWidth:0];
        _titleLabel.text = @"欢迎回来";
        _titleLabel.alpha = 0;
    }
    return _titleLabel;
}






@end











